﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using UBCon.Core.Primitives;

namespace UBCon.Navigation
{
    public class NavigationItem:ListBoxItem
    {
        #region Constructors

        static NavigationItem() 
        {
            Type ownerType = typeof(NavigationItem);
            NavigationItem.DefaultStyleKeyProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(ownerType));
            NavigationItem.PaddingProperty.OverrideMetadata(ownerType, 
                new FrameworkPropertyMetadata(new Thickness(4, 0, 0, 0), 
                    new PropertyChangedCallback(OnPaddingPropertyChanged),
                    new CoerceValueCallback(CoercePaddingProperty)));
        }

        public NavigationItem() 
        {
            RenderTransformOrigin = new Point(.5, .5);
            LayoutTransform = new RotateTransform() {Angle=-90 };
        }
        #endregion

        #region Properties

        internal bool IsSelectable 
        {
            get 
            {
                return isSelectable;
            }
            set 
            {
                isSelectable = value;
            }
        }

        #endregion

        #region Depenency Property Changed Callbacks

        private static void OnPaddingPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) 
        {
        
        }
        
        private static object CoercePaddingProperty(DependencyObject sender, object value) 
        {
            NavigationItem item = sender as NavigationItem;
            Thickness pendingValue = (Thickness)value;
            item.thick.Left = pendingValue.Bottom;
            item.thick.Top = pendingValue.Left;
            item.thick.Right = pendingValue.Top;
            item.thick.Bottom = pendingValue.Right;
            return item.thick;
        }
        #endregion

        #region Overrides

        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (!IsSelectable) 
            {
                e.Handled = true;
            }
            base.OnMouseLeftButtonDown(e);
        }
        #endregion

        #region Methods
        #endregion

        #region Event Handlers
        #endregion

        #region Fields
        private bool isSelectable = true;
        private Thickness thick = new Thickness();
        #endregion

        #region Events
        #endregion
    }
}
